﻿Imports Microsoft.WindowsAzure.StorageClient
Imports DelSole.BlobService

Public Class CreateContainerWindow

    Dim blobSvc As BlobService
    Private endPoint As String

    Private Sub CancelButton_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs)
        Me.Close()
    End Sub

    Private Sub CreateButton_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs)
        Dim result As Boolean

        If String.IsNullOrEmpty(Me.ContainerTextBox.Text) Then
            MessageBox.Show("Please enter a valid container name", "", MessageBoxButton.OK, MessageBoxImage.Exclamation)
            Exit Sub
        End If

        Try
            blobSvc.CreateContainer(Me.ContainerTextBox.Text.ToLower, CBool(Me.AccessControlCheckBox.IsChecked))
            result = True

        Catch ex As StorageServerException
            result = False
            MessageBox.Show("An error occurred on the Blob storage:" + Environment.NewLine + _
                            ex.ToString)
        Catch ex As Exception
            result = False
            MessageBox.Show(ex.ToString)
        Finally
            Me.DialogResult = result
        End Try

        Me.Close()
    End Sub

    Public Sub New(ByVal blobSvc As BlobService, ByVal blobEndPoint As String)

        ' This call is required by the designer.
        InitializeComponent()

        ' Add any initialization after the InitializeComponent() call.
        Me.blobSvc = blobSvc
        Me.endPoint = blobEndPoint
    End Sub
End Class
